// pages/list/list.js
const get = require('../../utils/common.js')
const app = getApp();
Page({

  /**
   * 页面的初始数据
   */
  data: {
    goodList: [],
    HomeIndex: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {

    let that = this
    wx.getStorage({
      key: 'telNum',
      success: function (res) {
        that.setData({ telNum: res.data })
      }
    })
    let telNum = that.options.telNum || that.data.telNum

    let goodList = that.data.goodList
    let from_detail = options.from_detail
    that.setData({
      from_detail
    })
    get.getData('/goods/goodslist', {}).then(res => {
      console.log("list-res", res)
      var listCon = res.data.data
      var HomeIndex = that.data.HomeIndex

      that.saixuan_link_type(listCon)
      that.setData({
        telNum: telNum
      })
    }).catch(err => {

    })
  },
  saixuan_link_type(listCon) {
    var goodList_goods = [];
    var goodList_artical = [];
    //筛选条件
    listCon.map((Item, index) => {
      //goodList_goods
      if (Item.link_type == 1) {
        goodList_goods.push({
          ...Item
        })
        this.setData({
          goodList_goods: goodList_goods
        })
        console.log("goodList_goods", this.data.goodList_goods)
      }
      //goodList_artical
      if (Item.link_type == 2) {
        goodList_artical.push({
          ...Item
        })
        this.setData({
          goodList_artical: goodList_artical
        })
        console.log("goodList_artical", this.data.goodList_artical)
      }
    })
    console.log(this.data.goodList_artical, this.data.goodList_goods)
  },
  fenlei(e) {
    var index = parseInt(e.currentTarget.dataset.index)
    this.setData({
      HomeIndex: index
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function () {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {

  }
})